home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / ntail / ntail.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  7.5 KB  |  249 lines

  1. /* ntail.h: */
  2.  
  3. /*
  4.  * @(#) $Header: /xtel/pp/pp-beta/Tools/ntail/RCS/ntail.h,v 6.0 1991/12/18 20:32:10 jpo Rel $
  5.  *
  6.  * $Log: ntail.h,v $
  7.  * Revision 6.0  1991/12/18  20:32:10  jpo
  8.  * Release 6.0
  9.  *
  10.  *
  11.  */
  12.  
  13.  
  14.  
  15. #ifndef _H_NTAIL
  16. #define _H_NTAIL
  17.  
  18. #include "util.h"    /* to get system defn */
  19.  
  20. /*
  21.  * @(#) xtail.h 2.1 89/07/26 19:16:49
  22.  *
  23.  * Package:    xtail version 2
  24.  * File:    xtail.h
  25.  * Description:    header definitions
  26.  *
  27.  * Mon Jul 10 02:56:22 1989 - Chip Rosenthal <chip@vector.Dallas.TX.US>
  28.  *    Original composition.
  29.  */
  30.  
  31.  
  32.  
  33. /*****************************************************************************
  34.  *
  35.  * Start of Site-Specific Customizations
  36.  *
  37.  *****************************************************************************/
  38.  
  39. /*
  40.  * Define one of the following.  It says how to use your "directory" library.
  41.  */
  42. /*#define DIR_XENIX    /* include <sys/ndir.h>, use "struct direct"    */
  43. #define DIR_BSD    /* include <ndir.h>, use "struct direct"    */
  44. /*#define DIR_SYSV    /* include <dirent.h>, use "struct dirent"    */
  45.  
  46. /*
  47.  * Define one of the following.  It specifies the return type of "signal()".
  48.  */
  49. /*#define SIGTYPE    int    /* declare as "int (*signal)()"        */
  50. /*#define SIGTYPE    void    /* declare as "void (*signal)()"    */
  51. #if !defined(SVR3) && !defined(SVR4) && !defined(SUNOS4) && !defined(BSD44) && !defined(ultrix)
  52. #define SIGTYPE     int
  53. #else
  54. #define SIGTYPE    void
  55. #endif
  56.  
  57. /*
  58.  * STATUS_ENAB    If defined, a SIGINT causes a summary of the opened files to
  59.  *        be displayed, and a SIGQUIT terminates the program.  If not
  60.  *        defined, these signals act normally.
  61.  */
  62. #define STATUS_ENAB    /**/
  63.  
  64. /*
  65.  * SLEEP_TIME    An iteration through the checking loop is performed once
  66.  *        per this many seconds.
  67.  */
  68. #define SLEEP_TIME    1
  69.  
  70. /*
  71.  * MAX_OPEN    This number of most recently changed files is kept open, and
  72.  *        they are checked every iteration through the checking loop.
  73.  *        Keeping these files open improves the performance because we
  74.  *        can use "fstat()" rather than "stat()".  Keeping too many
  75.  *        files open may overflow your open file table, and will reduce
  76.  *        performance by checking more files more frequently.
  77.  */
  78. #define MAX_OPEN    6
  79.  
  80. /*
  81.  * CHECK_COUNT    Everything besides open files are checked once per this
  82.  *        many iterations through the checking loop.
  83.  */
  84. #define CHECK_COUNT    5
  85.  
  86. /*
  87.  * MAX_ENTRIES    The maximum number of entries in any list.  It can be fairly
  88.  *        large -- each unused entry only eats 3*sizeof(char*) bytes.
  89.  */
  90. #define MAX_ENTRIES    512
  91.  
  92.  
  93. /*****************************************************************************
  94.  *
  95.  * End of Site-Specific Customizations
  96.  *
  97.  *****************************************************************************/
  98.  
  99.  
  100. #define TRUE 1
  101. #define FALSE 0
  102.  
  103. #define Dprintf        if ( !Debug ) ; else (void) fprintf
  104.  
  105.  
  106. /*
  107.  * Codes returned by the "stat_entry()" procedure.
  108.  */
  109. #define ENTRY_ERROR    0    /* stat error or permissions error    */
  110. #define ENTRY_SPECIAL    1    /* entry is a special file        */
  111. #define ENTRY_FILE    2    /* entry is a regular file        */
  112. #define ENTRY_DIR    3    /* entry is a directory            */
  113. #define ENTRY_ZAP    4    /* specified entry doesn't exist    */
  114.  
  115.  
  116. /*
  117.  * Diagnostic message codes.
  118.  *   The ordering of codes must correspond to the "mssg_list[]" defined below.
  119.  */
  120. #define MSSG_NONE    0    /* no message - just reset header    */
  121. #define MSSG_BANNER    1    /* display banner for file output    */
  122. #define MSSG_CREATED    2    /* file has been created        */
  123. #define MSSG_ZAPPED    3    /* file has been deleted        */
  124. #define MSSG_TRUNC    4    /* file has been truncated        */
  125. #define MSSG_NOTAFIL    5    /* error - not a regular file or dir    */
  126. #define MSSG_STAT    6    /* error - stat() failed        */
  127. #define MSSG_OPEN    7    /* error - open() failed        */
  128. #define MSSG_SEEK    8    /* error - lseek() failed        */
  129. #define MSSG_READ    9    /* error - read() failed        */
  130. #define MSSG_UNKNOWN    10    /* unknown error - must be last in list */
  131.  
  132.  
  133. #ifdef INTERN
  134. #   define EXTERN
  135. #else
  136. #   define EXTERN extern
  137. #endif
  138.  
  139.  
  140. /*
  141.  * Each item we are watching is stored in a (struct entry_descrip).  These
  142.  * entries are placed in lists, which are managed as (struct entry_list).
  143.  *
  144.  * There are three lists maintained:
  145.  *
  146.  * List_file    All of the regular files we are watching.  We will try to
  147.  *        keep the MAX_OPEN most recently modified files open, and
  148.  *        they will be checked more frequently.
  149.  *
  150.  * List_dir    All of the directories we are watching.  If a file is created
  151.  *        in one of these directories, we will add it to "List_file".
  152.  *
  153.  * List_zap    All the entries which don't exist.  When something appears
  154.  *        under one of these names, the entry will be moved to either
  155.  *        "List_file" or "List_dir", as appropriate.
  156.  */
  157.  
  158. struct entry_descrip {
  159.     char *name;        /* pathname to the entry            */
  160.     int fd;        /* opened fd, or <= 0 if not opened        */
  161.     long size;        /* size of entry last time checked        */
  162.     long mtime;        /* modification time last time checked        */
  163. };
  164.  
  165. struct entry_list {
  166.     struct entry_descrip *list[MAX_ENTRIES];
  167.     int num;
  168. };
  169.  
  170. /*
  171.  * The lists of entries being watched.
  172.  */
  173. EXTERN struct entry_list List_file;    /* regular files        */
  174. EXTERN struct entry_list List_dir;    /* directories            */
  175. EXTERN struct entry_list List_zap;    /* nonexistent entries        */
  176.  
  177.  
  178. /*
  179.  * List sorting status.
  180.  *   This flag indicates that "List_file" is sorted, and the right entries
  181.  *   are open.  Anything which possibly effects this state (e.g. an entry
  182.  *   is added to "List_file", the mtime of a file is changed, etc.) must set
  183.  *   this flag FALSE.  We will periodically check this flag and call the
  184.  *   "fixup_open_files()" procedure to resort and organize the list.
  185.  */
  186. EXTERN int Sorted;
  187.  
  188.  
  189. /*
  190.  * Entry status control flag.
  191.  *   The procedures which manipulate entries will reset the status information
  192.  *   if this flag is TRUE.  When initializing the lists we want this FALSE.
  193.  *   For example, consider the file size.  When initializing we want to use
  194.  *   the current file size, otherwise we would dump the file from the beginning.
  195.  *   However, later when we notice things are created we want to reset the
  196.  *   size to zero so that we do dump from the beginning.
  197.  */
  198. EXTERN int Reset_status;
  199.  
  200.  
  201. /*
  202.  * Debugging output flag.
  203.  */
  204. EXTERN int Debug;
  205.  
  206.  
  207. /*
  208.  * Diagnostic messages produced by the "message()" procedure.
  209.  *   The first "%s" is the entry name.  The second "%s" is the errno descrip.
  210.  */
  211. #ifdef INTERN
  212.     char *mssg_list[] = {
  213.     NULL,                            /*MSSG_NONE   */
  214.     "\n*** %s ***\n",                    /*MSSG_BANNER */
  215.     "\n*** '%s' has been created ***\n",            /*MSSG_CREATED*/
  216.     "\n*** '%s' has been deleted ***\n",            /*MSSG_ZAPPED */
  217.     "\n*** '%s' has been truncated - rewinding ***\n",    /*MSSG_TRUNC  */
  218.     "\n*** error - '%s' not a file or dir - removed ***\n",    /*MSSG_NOTAFIL*/
  219.     "\n*** error - couldn't stat '%s' (%s) - removed ***\n",/*MSSG_STAT   */
  220.     "\n*** error - couldn't open '%s' (%s) - removed ***\n",/*MSSG_OPEN   */
  221.     "\n*** error - couldn't seek '%s' (%s) - removed ***\n",/*MSSG_SEEK   */
  222.     "\n*** error - couldn't read '%s' (%s) - removed ***\n",/*MSSG_READ   */
  223.     "\n*** error - unknown error on file '%s' ***\n",    /*MSSG_UNKNOWN*/
  224.     };
  225. #else
  226.     extern char *mssg_list[];
  227. #endif
  228.  
  229.  
  230. /*
  231.  * Entry managment procedures.
  232.  */
  233. struct entry_descrip *new_entry();    /* create a new entry and add to list */
  234. void move_entry();            /* move an entry between lists          */
  235. void rmv_entry();            /* remove an entry from a list          */
  236. int stat_entry();            /* get the inode status for an entry  */
  237. int open_entry();            /* open an entry              */
  238.  
  239. /*
  240.  * Miscelaneous procedures.
  241.  */
  242. void fixup_open_files();        /* manage the open files          */
  243. int scan_directory();            /* scan a dir for files not on a list */
  244. void message();                /* standard message interface          */
  245. void show_status();            /* display currently opened files     */
  246.  
  247.  
  248. #endif
  249.